﻿#include <map>
#include "Reflector.h"
  
static std::map< string,ClassInfo*> *classInfoMap = nullptr;
using namespace std;

IMPLEMENT_CLASS_INHERIT(Object)

bool Object::Register(ClassInfo* ci)
{
    if(!classInfoMap)
    {
        classInfoMap = new std::map< string,ClassInfo*>();
    }
    if(ci)
    {
        if(classInfoMap->find(ci->m_className) == classInfoMap->end())
        {
            classInfoMap->insert(std::map<string,ClassInfo*>::value_type(ci->m_className,ci));
        }
    }
    return true;
}

Object* Object::MakeObject(std::string name)
{
    std::map< string,ClassInfo*>::const_iterator iter
            = classInfoMap->find(name);
    if(classInfoMap->end() != iter)
    {
        return iter->second->CreateObject();
    }   
    return nullptr;
}
 
bool Register(ClassInfo* ci)
{
    return Object::Register(ci);
}
